package com.dq.domain.setup;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.org.Org;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;

/**
 * @Author luchangtong
 * @Date 2019/11/28 15:13
 */
@Data
@Entity
@ApiModel("比例设置")
public class ReturnCommission extends BaseEntity implements VO.ToVO{
    @ApiModelProperty("门店")
    @ManyToOne
    protected Org sysDept;

    @ApiModelProperty("返佣比例")
    protected BigDecimal proportion;

    @ApiModelProperty("比例类型")
    @Enumerated(EnumType.ORDINAL)
    protected ProportionType proportionType;

    public enum  ProportionType{
        rakeBack("返佣"),
        integarl("积分");
        public String name;
        ProportionType(String name){
            this.name = name;
        }
    }

    @Data
    @ApiModel(value = "返佣设置视图")
    public static class Vo implements VO {
        protected Long id;
        @ApiModelProperty("返佣比例")
        protected BigDecimal proportion;

        protected String proportionTypeCN;
        protected String proportionTypeEN;

    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.proportion = this.getProportion()!=null?this.getProportion().multiply(new BigDecimal("100")):BigDecimal.ZERO;
        vo.proportionTypeCN = this.getProportionType() != null ? this.getProportionType().name:"";
        vo.proportionTypeEN = this.getProportionType() != null ? this.getProportionType().toString():"";
        return vo;
    }
}
